package shuogg.test.servletbase;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

@SuppressWarnings(value = { "all" })
public class OutHtml extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        /* 输出一个html文件 */
        OutputStream out = resp.getOutputStream();
        //FileInputStream in = new FileInputStream("F:/表单例程.html");
        InputStream in = OutHtml.class.getResourceAsStream("/表单例程.html");
        IOUtils.copy(in, out);
        
        System.out.println("Html Output complete!");
        
        /* 配合测试ServletContext */
        ServletContext myservletContext = this.getServletContext();
        String attrFromServletContext =  (String) myservletContext.getAttribute("shuoGGID");
        System.out.println("AttributeGet:" + attrFromServletContext);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) {
    }
}
